using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{
    public class DangKyThiQG_DAO
    {
        public DataTable DSTSDangKy()
        {
            try
            {
                DataTable dt = new DataTable();
                SqlConnection con = new SqlConnection();
                DataProvider dp = new DataProvider();
                con = dp.ConnectionData();
                con.Open();

                SqlCommand cmd = con.CreateCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "sp_LayDSTSDangKy";

                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dt);
                con.Close();
                return dt;
            }
            catch (SqlException e)
            {
                throw e;
            }

        }

        public void ThemThiSinhVong1(ThiSinh_CMND_DTO tscmnd_dto, ref int MaTS, int MaCC, int MaNN, int MaKT)
        {
            try
            {
                DataTable dt = new DataTable();
                SqlConnection con = new SqlConnection();
                DataProvider dp = new DataProvider();
                con = dp.ConnectionData();
                con.Open();

                SqlCommand cmd = con.CreateCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "sp_TiepNhan";

                SqlParameter pr = new SqlParameter("@MaTS", MaTS);
                pr.Direction = ParameterDirection.Output;
                cmd.Parameters.Add(pr);

                pr = new SqlParameter("@TenTS", tscmnd_dto.HoTen);
                cmd.Parameters.Add(pr);

                pr = new SqlParameter("@DiaChi", tscmnd_dto.DiaChi);
                cmd.Parameters.Add(pr);

                pr = new SqlParameter("@CMND", tscmnd_dto.CMND);
                cmd.Parameters.Add(pr);

                pr = new SqlParameter("@NgaySinh", tscmnd_dto.NgaySinh);
                cmd.Parameters.Add(pr);

                pr = new SqlParameter("@MaNN", MaNN);
                cmd.Parameters.Add(pr);

                pr = new SqlParameter("@MaCC", MaCC);
                cmd.Parameters.Add(pr);

                pr = new SqlParameter("@MaKT", MaKT);
                cmd.Parameters.Add(pr);

                cmd.ExecuteNonQuery();
                
                string str = cmd.Parameters["@MaTS"].Value.ToString();
                MaTS = Convert.ToInt32(str);

                con.Close();
                
            }
            catch (SqlException e)
            {
                throw e;
            }

        }
    }
}
